﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Space2D_Utils
{
	public class AABB
	{
		public AABB()
		{
			R = new Vector2d(0, 0);
			Position = new Vector2d(0, 0);
			Size = new Vector2d(0, 0);
		}

		public AABB(Vector2d pos, Vector2d r)
		{
			Position = pos;
			SetSize(r);
		}

		public void SetSize(double rx, double ry)
		{
			R = new Vector2d(rx, ry);
			Size = new Vector2d(rx + rx, ry + ry);
		}

		public void SetSize(Vector2d r)
		{
			R = r;
			Size = new Vector2d(r.X + r.X, r.Y + r.Y);
		}

		public static bool TestAABB(AABB a, AABB b)
		{
			double r;

			r = a.R.X + b.R.X; if ((a.Position.X - b.Position.X + r) > r + r) return false;
			r = a.R.Y + b.R.Y; if ((a.Position.X - b.Position.X + r) > r + r) return false;

			return true;
		}

		public Vector2d Position { get; protected set; }
		public Vector2d R { get; private set; }
		public Vector2d Size { get; private set; }
	}
}
